import { TrendingUpRounded } from "@material-ui/icons";
import * as echarts from "echarts";

type EChartsOption = echarts.EChartsOption;
export const xArr = [
  "星期一",
  "星期二",
  "星期三",
  "星期四",
  "星期五",
  "星期六",
  "星期天",
];
const yArr = [0, 0, 0, 0, 0, 0, 0];
export const setBarChartOpt = (data: barDataType[],title:string) => {
  data.map((value) => {
    let i = xArr.indexOf(value.key);
    if (i >= 0) {
      yArr[i] = value.value;
    }
  });
  const opt: EChartsOption = {
    tooltip: {
      show: true,
    },

    title: {
      text: title,
      textStyle: {
        fontWeight: 400,
        fontSize: 14,
        },
       
        left: "center",
    },
    legend: {
        show: true,
        orient: "vertical",
      left: "right",
    },
    xAxis: {
      type: "category",
      data: xArr,

      axisLabel: {
        interval: 0,
        fontSize: 12,
      },
    },
    yAxis: {
      type: "value",
      name: "元",
      splitLine: {
        show: false,
      },
      axisLine: {
        show: true,
      },
      axisTick: {
        show: true,
        length: 3,
        },
        axisLabel: {
            margin: 3,
            fontSize:10
      }
    },

    series: [
      {
        name: title.slice(-2),
        data: yArr,
        type: "bar",
        itemStyle: {
          color: "#C23531",
          // borderCap: 'round',
          borderRadius: [4, 4, 0, 0],
        },
        barWidth: 8,
        label: {
          show: true,
          position: "top",
          formatter: (params) => {
            return params.value === 0 ? "" : params.value.toString();
          },
        },
      },
    ],
    grid: {
      show: false,
    },
  };
  return opt;
};
